<template>
    <div>
        <el-form ref="form" :model="form" label-width="120px">
            <el-form-item label="用户名">
                <el-input v-model.trim="form.name"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model.trim="form.password" placeholder="请输入密码" show-password></el-input>
            </el-form-item>

            <el-form-item>
                <el-button type="primary" @click="goRegister">注册</el-button>
                <el-button type="primary" @click="onLogin" :plain="true">登录</el-button>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>
export default {
    data() {
        return {
            form: {
                name: '',
                password: '',
            },
        };

    },
    methods: {
        onLogin() {
            console.log('登录');
            // 在登录当中触发actions当中的login_a方法
            this.$store.dispatch('login_a',{
                user_name: this.form.name,
                password: this.form.password,
                //将$router 传递给actions login_a
                routerT: this.$router,
            });

           
        },
        // 点击注册按钮跳转到注册页面
        goRegister() {
            this.$router.push({
                name: 'register',
            });
        },
    },
}

</script>

<style lang="scss" scoped>
div {
    display: flex;
    align-items: center;
    justify-content: center;


    .el-form {
        width: 500px;
        height: 300px;
        background-image: url("~@/assets/bjt-01.webp");
        background-size: 100% 100%;

        .el-input {
            width: 300px;
            opacity: 0.5;
        }

        .el-form-item {
            height: 60px;
        }
    }
}
</style>